<template>
	<view>
		
		<u-toast ref="uToast"></u-toast><!-- 弹窗 -->
		<u-form ref="uForm">
			
			<u-form-item label="审批意见" label-width="150" style="padding: 10px;">
				<u-input v-model="handleOpinion" :type="type" placeholder="请输入" 
					 :auto-height="true" :border="true" :height="200" />
			</u-form-item>
		
			<view class="buttom-actions">
				<u-button class="buttom-btn" @click="submit" type="primary">{{buttonName}}</u-button>
			</view>
		</u-form>
	</view>
</template>

<script>
	
	import {
		subAudit
	} from '@/api/q1/workFlow/Engine/engine.js'
	export default {
		data() {
			return {
				type:'',// 通过、拒绝
				type:'textarea',
				buttonName:'提交',
				handleOpinion:'', // 审批意见
				data:{},
				encode:'',
				id:'',
				flowId:'',
			}
		},
		onLoad(option){
			const json = JSON.parse(option.params);
			this.id = json.id;
			this.type = json.type;
			this.data = json.data;
			this.encode = json.encode;
			this.flowId = json.flowId;
			this.buttonName = this.type == 'save' ? '确认通过' : '确认拒绝'
			// 设置标题
			uni.setNavigationBarTitle({
				title: this.buttonName
			})
			
		},
		methods:{
			submit(){
				
				var form = this.data != null ? this.data : {};
				form.flowId = this.flowId;
			
				const data = {
					copyIds:'',
					encode:this.encode,
					handleOpinion:this.handleOpinion,
					signImg:'',
					formData: form
				}
				console.log(this.id)
				console.log(JSON.stringify(data))
				
				
				try{
					subAudit(this.id, data).then(res =>{
						
						console.log(res)
						if(res.code == 200){
							this.$refs.uToast.show({
								title: "操作成功",
								type: 'success',
								duration: 1000,
								callback() {
									uni.navigateBack(); // 返回上一页
								}
							});
						}
						
					}).catch((err) => {
						console.log(err)
						
					});
				}catch(e){
					console.log(e)
				}
				
				
			}
		}
	}
</script>

<style>
</style>